package com.ideafactory.client.ybservice;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.ideafactory.client.ybservice.ybviewpager.LazyViewPager;

/**
 * Created by LiuShao on 2016/5/24.
 */
public class MyViewPager extends LazyViewPager{

    public MyViewPager(Context context) {
        super(context);
    }

    public MyViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void scrollTo(int x, int y){
        super.scrollTo(x, y);
    }


    private boolean isCanScroll = false;

    public void setScanScroll(boolean isCanScroll) {
        this.isCanScroll = isCanScroll;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {
        if(onYouchedScreen!=null){
            onYouchedScreen.touched();
        }
        if (isCanScroll) {
            return super.onInterceptTouchEvent(arg0);
        } else {
            return false;
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent arg0) {
        if (isCanScroll) {
            return super.onTouchEvent(arg0);
        } else {
            return false;
        }
    }

    public interface OnTouchedScreen{
        void touched();
    }
    public OnTouchedScreen onYouchedScreen;

    public void setOnTouchedScreen(OnTouchedScreen onYouchedScreen) {
        this.onYouchedScreen = onYouchedScreen;
    }
}